﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QThread>
#include <QPushButton>
#include <QLabel>
#include <QSemaphore>
#include <QMutex>

// 共享资源和信号量
extern QSemaphore semaphore;
extern QList<int> sharedData;
extern QMutex mutex;

// 消费者线程类
class ConsumerThread : public QThread {
    Q_OBJECT

public:
    ConsumerThread(int id, QObject *parent = nullptr) : QThread(parent), threadId(id) {}
    void run() override;

signals:
    void dataConsumed(int threadId, int value);

private:
    int threadId;
};


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void startThreads();
    void updateStatus(int threadId, int value);

private:
    QPushButton *startButton;
    QLabel *statusLabel;
    QList<ConsumerThread*> threads;
};
#endif // MAINWINDOW_H
